package ubi.quando.App;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.osmdroid.util.GeoPoint;

public class EventMeeting extends EventBase {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	List<EventPickUp> mPickUps;
	List<Contact> mParticipants;

	public EventMeeting(GeoPoint dest, Date date, String creatorId,
			ArrayList<Contact> participants) {
		super(dest, date, creatorId);
		mParticipants = new ArrayList<Contact>();

		if (participants != null) {
			for (Contact c : participants) {
				mParticipants.add(c);
			}
		}

		mPickUps = new ArrayList<EventPickUp>();
	}

	protected void writeObject(ObjectOutputStream out) throws IOException {
		super.writeObject(out);
		int size = mParticipants.size();
		out.writeInt(size);
		for (int i = 0; i < size; ++i) {
			out.writeObject(mParticipants.get(i));
		}

	}

	protected void readObject(ObjectInputStream in) throws IOException,
			ClassNotFoundException {
		super.readObject(in);
		int size = in.readInt();
		mParticipants = new ArrayList<Contact>();
		for (int i = 0; i < size; ++i) {
			Object temp = in.readObject();
			if (temp != null) {
				Contact contact = (Contact) temp;
				mParticipants.add(contact);
			}
		}
	}
	
	public void addParticipant(Contact contact)
	{
		if(mParticipants == null)
		{
			mParticipants = new ArrayList<Contact>();
		}
		mParticipants.add(contact);
	}

	public List<Contact> getParticipants() {
		return mParticipants;
	}

	@Override
	public EventType getType() {
		return EventType.MEETING;
	}

	public void setPickUps(ArrayList<EventPickUp> pickups) {
		if(mPickUps == null)
		{
			mPickUps = new ArrayList<EventPickUp>();
		}
		mPickUps.addAll(pickups);
	}

	public void addPickUp(EventPickUp pickup) {
		if(mPickUps == null){
			mPickUps = new ArrayList<EventPickUp>();
		}
		mPickUps.add(pickup);
		
	}

}
